package org.domain.sisbreve.session;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.jboss.seam.Component;
import org.jboss.seam.annotations.In;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.faces.FacesMessages;

/**
 * @author hugoalexandre
 *
 */
public class BaseBean implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@In
	public FacesMessages facesMessages;

	protected FacesContext getContext() {
		return FacesContext.getCurrentInstance();
	}

	protected HttpServletResponse getResponse() {
		return (HttpServletResponse) getContext().getExternalContext().getResponse();
	}


	protected HttpServletRequest getRequest() {
		return (HttpServletRequest) getContext().getExternalContext().getRequest();
	}

	protected ServletContext getServletContext() {
		return (ServletContext) getContext().getExternalContext().getContext();
	}

	public String getParameter(String name) {
		return getRequest().getParameter(name);
	}


	protected HttpSession getSession() {
		return getRequest().getSession();
	}

	protected Object retrieveComponent(String componentName) {
		return Component.getInstanceFromFactory(componentName);
	}

	protected void removeComponent(String componentName) {
		Contexts.removeFromAllContexts(componentName);
	}

	@SuppressWarnings("deprecation")
	public void addMsg(String msg, Object... params) {
		facesMessages.add(FacesMessage.SEVERITY_INFO, msg, params);
	}

	@SuppressWarnings("deprecation")
	public void addMsgBundle(String key, Object... params) {
		facesMessages.addFromResourceBundle(FacesMessage.SEVERITY_INFO, key, params);
	}


	@SuppressWarnings("deprecation")
	public void addMsgErro(String msg, Object... params) {
		facesMessages.add(FacesMessage.SEVERITY_ERROR, msg, params);
	}
	
	@SuppressWarnings("deprecation")
	public void addMsgErroBundle(String key, Object... params) {
		facesMessages.addFromResourceBundle(FacesMessage.SEVERITY_ERROR, key, params);
	}



}
